package ${pPackage}.swagger;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * Swagger2Config配置类
 *
 * @author hl
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
class SwaggerConfiguration {

  @Bean
  public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
      .groupName("默认接口")
      .host("192.169.1.1")
      .apiInfo(apiInfo())
      .select()
      //API 路径
      .apis(RequestHandlerSelectors.basePackage("${pPackage}.controller"))
      .paths(PathSelectors.any())
      .build();
  }
// 可以创建多个分组
//  @Bean
//  public Docket createRestApiB() {
//    return new Docket(DocumentationType.SWAGGER_2)
//      .groupName("默认接口")
//      .host("192.169.1.1")
//      .apiInfo(apiInfo())
//      .select()
//      //API 路径
//      .apis(RequestHandlerSelectors.basePackage("${pPackage}.controller"))
//      .paths(PathSelectors.any())
//      .build();
//  }


  private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
      .title("APIDOC")
      .description("微服务接口文档")
      .termsOfServiceUrl("https://www.xxx.com/api")
      .contact(new Contact("胡雷", "https://gitee.com/javaweb-h5/MicroService", "523387582@qq.com"))
      .version("1.0")
      .build();
  }


}
